<?php

use rocotito\businessLogic\BL_place;
require_once('businessLogic.php');

switch($_GET["s"]) {
	
	case 'SearchPlaceByName':
		SearchPlaceByName($_GET["q"]);
		break;
	default :
		echo 'no se encontro el procedimiento';
		
		
}

function SearchPlaceByName($name){
	$bl_place = new BL_place();
	$bl_place->BL_place($name);
	$places = $bl_place->getPlace();
	$return_array = array();
	foreach($places as $place){
		$row_array['cod_place'] = $place->getCod_place();
		$row_array['name'] = $place->getName();
		$row_array['phone'] = $place->getPhone();
		$row_array['delivery'] = $place->getDelivery();
		$row_array['website'] = $place->getWebsite();
		$row_array['email'] = $place->getEmail();
		$row_array['description'] = utf8_encode($place->getDescription());
		$typefood_array = $place->getTypefood();
		$row_array['typefood'] = array();
//		$row_array = array_map('htmlentities', $row_array);
		foreach($typefood_array as $typefood){
			$typefood_s['cod_type_food'] = $typefood->getCod_type_food();
			$typefood_s['name'] = $typefood->getName();
//			$typefood_s = array_map('htmlentities', $typefood_s);
			array_push($row_array['typefood'],$typefood_s);
		}
		
		$address_array =  $place->getAddress();
		$row_array['address'] = array();
		foreach($address_array as $address){
			$address_s['cod_address'] = $address->getCod_address();
			$address_s['place_cod_place'] = $address->getPlace_cod_place();
			$address_s['address_line_1'] = $address->getAddress_line_1();
			$address_s['address_line_2'] = $address->getAddress_line_2();
			$address_s['zip'] = $address->getZip();
			$address_s['reference'] = $address->getReference();
			$address_s['phone'] = $address->getPhone();
//			$address_s = array_map('htmlentities', $address_s);
			array_push($row_array['address'],$address_s);
		}
		array_push($return_array,$row_array);
	}
	
	//header('Content-type: application/json; charset=iso-8859-1');
	echo json_encode($return_array);
}

?>